<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The forward purpose</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="yaf-controller-abstract.display.html">« Yaf_Controller_Abstract::display</a></li>
      <li style="float: right;"><a href="yaf-controller-abstract.getinvokearg.html">Yaf_Controller_Abstract::getInvokeArg »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.yaf-controller-abstract.html">Yaf_Controller_Abstract</a></li>
    <li>The forward purpose</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="yaf-controller-abstract.forward" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yaf_Controller_Abstract::forward</h1>
  <p class="verinfo">(Yaf &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Controller_Abstract::forward</span> &mdash; <span class="dc-title">The forward purpose</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yaf-controller-abstract.forward-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Yaf_Controller_Abstract::forward</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$module</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$controller</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$action</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$paramters</code><span class="initializer"> = ?</span></span><br>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
    将当前的请求转交给另外的Action.
   </p>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
     调用<span class="methodname"><strong>Yaf_Controller_Abstract::forward()</strong></span>以后,
     不会直接立即跳转到目的Action执行, 而是会在当前的Action执行完成后,
     下一轮的DispatchLoop中, 交给目的Action.
    </p>
    <p class="para">
      所以, 如果你希望立即跳转到目的Action,
      那么请使用return结束当前的执行流程.
    </p>
   </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-yaf-controller-abstract.forward-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">module</code></dt>

    <dd>

     <p class="para">
       要跳转的目的Action的Module, 如果是NULL, 则默认Module会被采用.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">controller</code></dt>

    <dd>

     <p class="para">
       要跳转的目的Action的Controller, 如果是NULL, 则默认Controller会被采用.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">action</code></dt>

    <dd>

     <p class="para">
      要跳转的目的Action.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">paramters</code></dt>

    <dd>

     <p class="para">
      跳转参数,
      可以在目的Action中通过<span class="methodname"><strong>Yaf_Request_Abstrace::getParam()</strong></span>来获取.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 examples" id="refsect1-yaf-controller-abstract.forward-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-3891">
   <p><strong>示例 #1 <span class="function"><strong>Yaf_Controller_Abstract::forward()</strong></span>例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">IndexController&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Yaf_Controller_Abstract<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">indexAction</span><span style="color: #007700">(){&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$logined&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">"login"</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$logined</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">forward</span><span style="color: #007700">(</span><span style="color: #DD0000">"login"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"from"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Index"</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;跳转到login&nbsp;Action<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;return立即结束当前的执行流程,&nbsp;跳转到目的Action<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;而这里的FALSE是告诉Yaf不要自动渲染这个Action的视图<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;other&nbsp;processes<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">loginAction</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"login,&nbsp;redirected&nbsp;from&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">_request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParam</span><span style="color: #007700">(</span><span style="color: #DD0000">"from"</span><span style="color: #007700">)&nbsp;,&nbsp;</span><span style="color: #DD0000">"&nbsp;action"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
   login, redirected from Index action
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-yaf-controller-abstract.forward-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    return FALSE on failure
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-yaf-controller-abstract.forward-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><strong>Yaf_Request_Abstrace::getParam()</strong></span></li>
  </ul>
 </div>


</div></div></div></body></html>